package main

import (
	"github.com/gin-gonic/gin"
	_ "go-record/src/loggers"
	"log/slog"
	"net/http"
)

func main() {
	router := gin.Default()
	router.Any("/redirect", func(context *gin.Context) {
		printRequest(context)
		redirectUrl := context.Query("redirect")
		context.Header("Cache-Control", "no-cache, no-store, must-revalidate")
		context.Redirect(http.StatusFound, redirectUrl)
	})
	err := router.Run(":18080")
	if err != nil {
		slog.Error("err", "err", err)
	}
}

func printRequest(context *gin.Context) {
	// 查询请求URL后面拼接的参数
	fullPath := context.Request.RequestURI
	remoteAddr := context.Request.RemoteAddr
	slog.Info("Client", "path:", fullPath, "remoteAddr", remoteAddr)
	slog.Info("Header", "Header", context.Request.Header)

}
